/***************************************************************************
 *   Copyleft 2006-2007 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>			                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#ifndef __VECTOR3D_H__
#define __VECTOR3D_H__

#include <math.h>
#include "../../Types/Types.h"
#include "MathConstants.h"
#include "Vector2D.h"


class Vector3D {
public:
	union {
		struct {
			cFloat mValues[3];
		};
		struct {
			cFloat mX;
			cFloat mY;
			cFloat mZ;
		};
	};

	/**************************************************************
    * Constructors                                                *
    ***************************************************************/
	Vector3D(): mX(0.0f), mY(0.0f), mZ(0.0f) { }
	Vector3D(cFloat fX, cFloat fY, cFloat fZ): mX(fX), mY(fY), mZ(fZ) { }
	Vector3D(const Vector2D vect);
	Vector3D(const Vector3D& vect);

	/**************************************************************
    * Operators                                                   *
    ***************************************************************/
	Vector3D& operator+=(const Vector3D& vectB);
	Vector3D& operator-=(const Vector3D& vectB);
	Vector3D operator-() const;
	Vector3D& operator*=(const Vector3D& vectB);
	Vector3D& operator*=(const cFloat fFactor);
	Vector3D& operator=(const Vector3D& vectB);
	
	/**************************************************************
    * Friend functions                                            *
    ***************************************************************/
	friend Vector3D operator+(const Vector3D& vectA, const Vector3D& vectB);
	friend Vector3D operator-(const Vector3D& vectA, const Vector3D& vectB);
	friend Vector3D operator*(const Vector3D& vectA, const Vector3D& vectB);
	friend Vector3D operator*(const Vector3D& vectA, const cFloat fFactor);

	/**************************************************************
    * Math functions                                              *
    ***************************************************************/
	cVoid Set(cFloat fX, cFloat fY, cFloat fZ);
	inline cFloat Length() const;
	inline cFloat SqrLength() const;
	cVoid Normalize();
	cVoid FastNormalize();
	cFloat DotProduct(const Vector3D& vectB);
	cVoid CrossProduct(const Vector3D& vectA, const Vector3D& vectB);
};

#endif // __VECTOR3D_H__